
<html xlmns="http://www.w3.org/1999/xhtml">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<meta name="author" content="lamtoan" />

	<title>ADMIN PANEL</title>
    <link type="image/x-icon" rel="shortcut icon" href="images/dnnicon.gif"/>
    <link href="css/login.css" rel="stylesheet" type="text/css" />
    <script type="text/javascript" language="javascript">
   
        function onload()
        {
            document.getElementById('username').focus();
        }
    
    </script>
</head>

<body onload="onload();">
<?php
    ini_set('display_errors',1);
    include ("lib_db.php");
	if(!isset($_SESSION)){ session_start();}
	$ten='';
	if(isset($_SESSION['ten'])){$ten=$_SESSION['ten'];unset($_SESSION['ten']);}
	if(isset($_POST['login'])){
	if(isset($_REQUEST['username'])){$username=$_REQUEST['username'];}
	if(isset($_REQUEST['password'])){$pass=$_REQUEST['password'];}
	$error="";$checkLogin=1;$user=0;
	$sql="select * from user where user='$username'";
	//echo $sql;exit();
	$user=select_one($sql);
	if(!$user){
		$checkLogin=0;
		$error="Không tồn tại username";
		echo "<script>alert('Không tồn tại username');window.location='login.php';</script>";exit();
	}else{$_SESSION['ten']=$user['user'];
		if(md5($pass)!=$user['pass']){
			$checkLogin = 0;
			$error="Password không đúng";
			echo "<script>alert('Password không đúng'); window.location='login.php';</script>";exit();
		}else{if($user['level']==1){$checkLogin=1;}else{$checkLogin=0;$error="Tài khoản này không có quyền truy cập cào trang quản trị";
		echo "<script>alert('Tài khoản này không có quyền truy cập cào trang quản trị');window.location='login.php';</script>";exit();
		}
	}
	if ($checkLogin==1){
		$_SESSION['user'] = $user;
		header("Location:index.php");
		exit();
	}	
}
}
?>

<div class="wrapper">
	<div class="header">
		<div class="logo"><img src="images/logo.jpg"/></div>
	</div>
	<div class="clear"></div>
	
		<div class="content" style="float:left;">
			<div class="formlogin">
				<div class="title"><h3>ADMIN ĐIỆP BẮP 1992</h3></div>
				<div class="forgotpass"><a href="#" title="Forgot password">Forgot Password</a></div>
				<div class="formcontent">
				<form action="login.php" method="post">
				<fieldset>
					
						<dl>
							<dt><label>Username:</label></dt>
							<dd><input type="text" id="username" value="<?php echo $ten;?>" name="username" size="54"/></dd>
						</dl>
						<dl>
							<dt><label>Password:</label></dt>
							<dd><input type="password" id="password" name="password" size="54"/></dd>
						</dl>
						<dl>
							<dt></dt>
							<dd>
								<input type="checkbox" name="remember" value=""/>
								<label>Remember me</label>
							</dd>
						</dl>
						<dl>
						<dt></dt>
						<dd><input class="enter" name="login" type="submit" value="Enter"/></dd>
						</dl>
						
				 </fieldset>
				</form>				
				</div>
			</div>
		</div>
	
	<div class="clear"></div>
	<div class="footer"></div>
</div>
</body>
</html>